package lesson16;

import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

public class MyAtomicInteger {

    public static void main(String[] args) throws InterruptedException {
        AtomicInteger count = new AtomicInteger(0);
        ExecutorService executorService = Executors.newFixedThreadPool(16);
        for(int i = 0; i < 1000; i++){
            executorService.submit(new MyTask(count));
        }
        Thread.sleep(1000);

        System.out.println(count.get());
    }

    static class MyTask implements Runnable{

        private AtomicInteger count;

        MyTask(AtomicInteger count){
            this.count = count;
        }

        @Override
        public void run() {
            count.incrementAndGet();
        }
        
    }
}
